package com.iaiai.calendar.activity;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.Display;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.iaiai.calendar.util.Utils;

/**
 * 
 * <p>
 * Title: CalendarTitleGridView.java
 * </p>
 * <p>
 * E-Mail: 176291935@qq.com
 * </p>
 * <p>
 * QQ: 176291935
 * </p>
 * <p>
 * Http: iaiai.iteye.com
 * </p>
 * <p>
 * Create time: 2012-1-2
 * </p>
 * 
 * @author 丸子
 * @version 0.0.1
 */
public class CalendarTitleView extends LinearLayout {

	private int[] weeks = new int[] { R.string.Sun, R.string.Mon, R.string.Tue,
			R.string.Wed, R.string.Thu, R.string.Fri, R.string.Sat };

	private Context mContext;

	public CalendarTitleView(Context context) {
		super(context);
		mContext = context;

		setView();
	}

	private void setView() {
		setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT));
		setBackgroundColor(R.color.title);
		setOrientation(LinearLayout.HORIZONTAL);

		for (int week : weeks) {
			TextView titleView = new TextView(mContext);
			titleView.setLayoutParams(new LayoutParams(getLayoutWidth(7),
					LayoutParams.WRAP_CONTENT));
			titleView.setTextColor(Color.WHITE);
			titleView.setTextSize(Utils.pxTodip(mContext, 20));
			titleView.setGravity(Gravity.CENTER);
			// if (week == R.string.Sun) {
			// btn.setBackgroundColor(color.title_day7);
			// } else if (week == R.string.Sat) {
			// btn.setBackgroundColor(color.title_day6);
			// } else {
			// btn.setBackgroundColor(color.title_day);
			// }
			titleView.setText(week);
			addView(titleView);
		}
	}

	/**
	 * 获得宽度
	 * 
	 * @param num
	 *            分割成几项
	 * @return
	 */
	private int getLayoutWidth(int num) {
		WindowManager windowManager = ((Activity) mContext).getWindowManager();
		Display display = windowManager.getDefaultDisplay();
		return display.getWidth() / num;
	}

}
